<?php 
	ini_set('display_errors', 1); 
	ini_set('error_reporting', 'E_error'); 		
	require_once "../includes/pagination.php";
				
	if($_REQUEST['by']=="asc")
	{
		$by='desc';
	}
	else
	{
		$by='asc';
	}
	
	if($_REQUEST['by']=="asc")
	{
		$asc_desc='asc';
	}
	else if($_REQUEST['by']=="desc")
	{
		$asc_desc='desc';
	}
	else
	{
		$asc_desc='desc';
	}
	
	if($_REQUEST['ord']=="1")
	{
		$ord_by='item_code';
	}
	else if($_REQUEST['ord']=="2")
	{
		$ord_by='i.item_id';
	}
	else if($_REQUEST['ord']=="3")
	{
		$ord_by='u.first_name';
	}
	else if($_REQUEST['ord']=="4")
	{
		$ord_by='o.order_amount';
	}
	else
	{
		$ord_by='order_id';
	}

?>		  
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Third Party Refund</td>
  </tr>
  <tr>
    <td height="577">
	 <table width="100%">
            <tbody>
		<tr>
			<td>
				<form name="frmSearchPro" action="" method="post">
				<table width="100%" border="0">
					<tr>
					    <td width="20%">Item Code</td>
					    <td width="30%"><input type="text" name="item_code" id="item_code" style="width: 150px;" value="<?php echo $_POST['item_code']?>" /></td>
					    <td width="20%">Order Amount</td>
					    <td width="30%">
						<input type="text" name="order_amount" id="order_amount" style="width: 150px;" value="<?php echo $_POST['order_amount']?>" />
					    </td>
					</tr>
					<tr>
						<td height="35" colspan="5" style="text-align:center"><input type="submit" name="btnSearchPro" value="Search" /></td>
					</tr>
				</table>
				</form>
			</td>
		</tr>
		
        </tbody></table>
	<br>
	<div style="overflow-x:scroll;">
	<table width="100%"  border="0" cellspacing="0">      
		<tr class="InnerHeader">
			<td class="line" width="25%"><a href="index.php?indirect_refund&ord=1&by=<?php echo $by;?>">Item Code</a></td>
			<td width="25%" class="line"><a href="index.php?indirect_refund&ord=2&by=<?php echo $by;?>">Product</a></td>
			<td width="25%" class="line"><a href="index.php?indirect_refund&ord=3&by=<?php echo $by;?>">Refunded To</td>
			<td width="25%" class="line"><a href="index.php?indirect_refund&ord=4&by=<?php echo $by;?>">Amount</a></td>
		</tr>
		
      
      <?php 
	  	  			
				 
				 $itemPerPage=25;	
				 $total=0;			
				if (isset($_GET['page']) && (int)$_GET['page'] > 0) 
				{
					$pageNumber = (int)$_GET['page'];		
				} 
				else 
				{
					$pageNumber = 1;		
				}
				$search='';
				if(isset($_POST['btnSearchPro'])) {
					
					$item_code		= $_POST['item_code'];		
					$order_amount			= $_POST['order_amount'];
					
					
					if($item_code!='')
					$search.= " AND item_code='".$item_code."'";
					
					if($tran_date!='')
					$search.=" AND tran_date='".$tran_date."'";
					
					 
					
				}
				//$sql_shocat="SELECT  *,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id  order BY order_id desc";//limit ".$pageNumber.", ".$itemPerPage."";				 
				$sql_shocat="SELECT *,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id left join tbl_items i on o.item_id=i.item_id  where refund=1 and order_comm_to_user_id!=order_comm_by_user_id $search order BY ".$ord_by."  ".$asc_desc."";
				
				 $rst_shocat=mysql_query(getPagingQuery($sql_shocat,$itemPerPage));
				 $numRows = mysql_num_rows($rst_shocat);
				 
				 $i=(int)(($itemPerPage*($pageNumber-1))+1);
				 
				 if($numRows>0) {				
					while($row_shocat = mysql_fetch_array($rst_shocat)) 
					{					
													
						$sqlSelItem="select p.* from tbl_items i left join tbl_product p  on i.product_id=p.product_id where item_id=".$row_shocat['item_id']."";
						$rstSelItem=mysql_query($sqlSelItem);
						$rowSelItem=mysql_fetch_array($rstSelItem);
						if(is_array($rowSelItem))
						{
							$product_name=$rowSelItem['product_name'];
						}						
						$sqlSelItem="select * from tbl_users where user_id='".$row_shocat['ordered_by']."'";
						$rstSelItem=mysql_query($sqlSelItem);
						$rowSelItem=mysql_fetch_array($rstSelItem);						
						if(is_array($rowSelItem))
						{
							$order_by=$rowSelItem['first_name'];
						}
						
						
								 
				 ?> 
					<tr>
					<td class="line"><?php echo ($row_shocat['item_code']);?></td>
					<td class="line"><?php echo $product_name;?></td>
					<td class="line"><?php echo $order_by;?></td>
					<td class="line"><?php echo $row_shocat['order_amount']?></td>
      				</tr><?php $i++;
					}
				} 	?>     
       </table>
	<div align="center">
		<?php		   
		   $link="tran_history&ord=".$_REQUEST['ord']."&by=".$asc_desc."";
		   echo $disp=getPagingLink($sql_shocat,$itemPerPage,$link);							   
		?>    
	</div>
	</div>
	</td>
 </tr>
 <tr>
 <td style="text-align:right;"></td>
 </tr>
</table>